using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Business.Entities.Notation;

namespace OR.Lazarus.Business.Entities.Notation.Lazarus
{
	/// <summary>
	/// Defines a set of rules for applying notation to field names.
	/// </summary>
   public class NotationDetail : EntityBase
   {
		protected System.String mName;
		protected string mDescription;
	
		protected Derived.MapCollection mMaps;

		public NotationDetail()
		{
			mMaps = new Derived.MapCollection();
			mMaps.ParentEntity = this;
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public Derived.MapCollection Maps
		{
			get
			{
				return ( mMaps );
			}
			set
			{
				mMaps = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
			XmlElement vMaps = ( XmlElement )pSource.SelectSingleNode( "maps", PersistenceConfig.Namespaces );
			
			if ( vMaps != null )
			{
				mMaps.LoadXml( vMaps );
			}
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "", "root", "" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "", "description", "" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			// Collections
			
			XmlElement	vCollection	= null;
			
			vCollection = mMaps.SaveXml( p_docContext );
			if ( vCollection != null )
			{
				vNewElement.AppendChild( vCollection );
			}

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.NotationDetail v_oReturn = new Derived.NotationDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections

			foreach ( Derived.MapDetail vDetail in mMaps )
			{
				v_oReturn.Maps.Add( vDetail.CloneTyped() );
			}
			
			return ( v_oReturn );
		}

		public virtual Derived.NotationDetail CloneTyped()
		{
			return ( ( Derived.NotationDetail )this.Clone() );
		}
   }
}
   